﻿package mortal.game.view.common.alertwins
{
    import com.gengine.core.frame.*;
    import com.mui.controls.*;

    public class TimerAlertWin extends CustomAlertWin
    {
        private var _secTimer:SecTimer;
        private var _btnLabel:String;
        private var _timeNO:Boolean;

        public function TimerAlertWin(param1:Number, param2:Number)
        {
            super(param1, param2);
            return;
        }// end function

        private function createTimer() : void
        {
            if (Alert.timerOut <= 0)
            {
                return;
            }
            if (!this._secTimer)
            {
                this._secTimer = new SecTimer(1, Alert.timerOut);
                this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            }
            this._secTimer.repeatCount = Alert.timerOut;
            if (!this._secTimer.running)
            {
                this._secTimer.start();
            }
            return;
        }// end function

        private function onTimerCompleteHandler(param1:SecTimer) : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            if (closeHandler != null)
            {
                if (this._timeNO)
                {
                    if (extendObj != null)
                    {
                        closeHandler(Alert.CANCEL, extendObj);
                    }
                    else
                    {
                        closeHandler(Alert.CANCEL);
                    }
                }
                else if (extendObj != null)
                {
                    closeHandler(Alert.OK, extendObj);
                }
                else
                {
                    closeHandler(Alert.OK);
                }
            }
            return;
        }// end function

        private function onEnterFrameHandler(param1:SecTimer) : void
        {
            var _loc_2:GButton = null;
            if (this._timeNO)
            {
                _loc_2 = getButtonByFlag(Alert.CANCEL);
            }
            else
            {
                _loc_2 = getButtonByFlag(Alert.OK);
            }
            if (_loc_2 != null)
            {
                _loc_2.label = this._btnLabel + "(" + param1.repeatCount + ")";
            }
            return;
        }// end function

        override protected function writeData() : void
        {
            super.writeData();
            this._timeNO = Alert.timerNO;
            if (this._timeNO)
            {
                this._btnLabel = Alert.calcelLabel;
                Alert.calcelLabel = Alert.calcelLabel + ("(" + Alert.timerOut + ")");
            }
            else
            {
                this._btnLabel = Alert.okLabel;
                Alert.okLabel = Alert.okLabel + ("(" + Alert.timerOut + ")");
            }
            this.createTimer();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            if (this._secTimer)
            {
                if (this._secTimer.running)
                {
                    this._secTimer.stop();
                }
                this._secTimer.dispose(param1);
                this._secTimer = null;
            }
            return;
        }// end function

    }
}
